﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using ScheduleMaker.ConfigManager;
using ScheduleMaker.DB.Domain;
using ScheduleMaker.DB.Domain.Core;
using ScheduleMaker.DB;
using ScheduleMaker.DB.CoreDAO;

namespace ScheduleMaker
{
    public partial class smAdmItemAddForm : Form
    {
        smAdminForm parentForm;

        public smAdmItemAddForm( smAdminForm _parentForm)
        {
            InitializeComponent();
            this.parentForm = _parentForm;
        }

        private void button1_Click(object sender, EventArgs e)
        { 
            // Dodawanie wyposażenia 
            if (regexpHelper.Instance.isClassroomNameCorrect(tbequiname.Text))
            {

                DB.Domain.Core.Equipment equi;
                EquipmentDAO equipmentDAO = DAOFactory.getEquipmentDAO(ConfigManager.ConfigManager.getConfiguration().Type);

                if (ConfigManager.ConfigManager.getConfiguration().Type == Mode.School)
                {
                    equi = new EquipmentSchool();
                }
                else
                {
                    equi = new EquipmentUniversity();
                }
                //room.Id = 21;
                equi.Name = tbequiname.Text;
                equi.Description = tbequidesc.Text;
                equipmentDAO.save(equi);

                MessageBox.Show("Wyposażenie zostało dodane", "Dodanie wyposażenia", MessageBoxButtons.OK, MessageBoxIcon.Information);
                this.parentForm.getEquipmentList();

                this.Dispose();
            }
            else
            {
                MessageBox.Show("Niepoprawna nazwa wyposażenia!", "Dodanie wyposażenia", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
        }
    }
}
